function initSearch(category) {
	query = "";
	var midPos = getMiddle(locArray);
	addMidMarker(midPos);
	console.log("Sending search to server: " + category);
	sendSearchToServer(midPos.lat(), midPos.lng(), query, category);
}

function onSearchResult(data) {
	deleteOverlays();
	console.log("deleted overlays");
	
	console.log("data from search: " + JSON.stringify(data));
	
	var features = data['features'];
	for (x in features) {
		var feature = features[x];
		var lat = feature.geometry.coordinates[1];
		var lng = feature.geometry.coordinates[0];
		
		var name = feature.properties.name;
		
		console.log("Place: " + name + ", location: " + lat + ", " + lng);
		addPlaceMarker(lat, lng, name);
	}
}

//find middle pos of all positions passed in the member info array
function getMiddle(memfo) {
	
	var latTotal = 0;
	var longTotal = 0;
	var count = 0;
	var marker;
	for (obj in memfo) {
	    //marker = google.maps.Marker(obj.marker);
		latTotal = latTotal + memfo[obj].marker.getPosition().lat();
		longTotal = longTotal + memfo[obj].marker.getPosition().lng();
		count = count + 1;
	}
	lat = (latTotal / count);
	lng = (longTotal / count);
	console.log(latTotal + " middle lat: " + lat);
	console.log(longTotal + " middle lng: " + lng);
	return new google.maps.LatLng(lat, lng);
}

function getDist() {
	var service = new google.maps.DistanceMatrixService();
	service.getDistanceMatrix(
	  { origins: [loc1],
	    destinations: [loc2],
	    travelMode: google.maps.TravelMode.DRIVING,
	    avoidHighways: false,
	    avoidTolls: false
	  }, function(response, status) {
		if (status == google.maps.DistanceMatrixStatus.OK) {
		    var origins = response.originAddresses;
		    var destinations = response.destinationAddresses;

		    for (var i = 0; i < origins.length; i++) {
		      var results = response.rows[i].elements;
		      for (var j = 0; j < results.length; j++) {
		        var element = results[j];
		        var distance = element.distance.text;
				//console.log(distance);
		        var duration = element.duration.text;
		        var from = origins[i];
		        var to = destinations[j];
		      }
		    }

		  }
	});
}

function getPlaces(loc, type) {
	console.log("location to get places from: " + loc);
	console.log("types of places looking for: " + type);
	//var url = "https://maps.google.com/maps/api/place/search/json?location=" +
	//	loc.lat()+","+loc.lng()+"&radius=500&types="+type+"&sensor=false&key=AIzaSyCwnAwS9cXR0bILeSp0xHyJhg4wCn7qkSo";
	

	var client = new simplegeo.PlacesClient('wt3NYwTFUaUVdzn2QUcKmnsTL8crFd9w');


	var address = "2659 alma street, palo alto, ca";

	client.searchFromAddress(address, {category: type, radius: 10}, function(err, data) {
	    if (err) {
	        console.error(err);
	    } else {
	        console.log("JSON from client search",JSON.stringify(data));
	    }
	});


//	var response = $.ajax(url, function (data) {
//		alert(data);
//	});
	/*
	count = response.data.length;
      for (i=0; i<count; i++)
	    {
		  marker = addMarker(response.data[i].geometry.location);
		  infowindow = new google.maps.InfoWindow({
			content: place.name
		  });
		  google.maps.event.addListener(marker, 'click', function() {
			infowindow.open(map,marker);
		  });
		  console.log(place.name);
        }
      }*/
}


/*

//https://maps.googleapis.com/maps/api/place/search/json?location=37.428899,-122.169857&radius=500&types=food&sensor=false&key=AIzaSyCwnAwS9cXR0bILeSp0xHyJhg4wCn7qkSo

*/